package com.qf.service.impl;

import com.qf.entity.Order;
import com.qf.entity.OrderDTO;
import com.qf.entity.OrderVO;
import com.qf.mapper.OrderVOMapper;
import com.qf.mapper.UserMapper;
import com.qf.service.OrderVOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 天--道--酬--勤
 *
 * @author LiangGaoQiang
 * @ClassName OrderVOServicemplI
 * @Date: 2025/5/1 21:20
 * @Description: 描述
 */
@Service
public class OrderVOServiceImpl implements OrderVOService {
    @Autowired
    private OrderVOMapper orderVOMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<OrderVO> fuzzyQueryOrder(OrderDTO orderDTO) {
        return orderVOMapper.fuzzyQueryOrder(orderDTO);
    }

    @Override
    public Boolean addOrder(Order order) {
        // 通过用户名获取用户id
        Long userId = userMapper.getIdByUserName(order.getUsername());
        order.setUserId(userId);    // 设置用户id
        order.setCreatedAt(new Date());  // 设置创建时间
        return orderVOMapper.addOrder(order);
    }

    @Override
    public Boolean updateOrder(Order order) {
        // 通过用户名获取用户id
        Long userId = userMapper.getIdByUserName(order.getUsername());
        order.setUserId(userId);    // 设置用户id
        return orderVOMapper.updateOrder(order);
    }

    @Override
    public void insertBatch(List<OrderVO> cachedDataList) {
        orderVOMapper.insertBatch(cachedDataList);
    }
}
